package com.cqq.print.business.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cqq.common.core.bean.PageInfoBean;
import com.cqq.print.business.dao.PProduceDetailDao;
import com.cqq.print.business.dao.domain.PProduceDetail;
import com.cqq.print.business.service.bean.PProduceDetailBean;


/**
 * @author generated
 * @date 2015-07-01
 */


@Service(value="pProduceDetailService")
public class PProduceDetailServiceImpl implements com.cqq.print.business.service.PProduceDetailService{

             @Autowired
             private PProduceDetailDao pProduceDetailDao;

			
			public int insertSelect(PProduceDetailBean ppDetail) {
				if(ppDetail==null||ppDetail.getProId()==null)
					return 0;
				PProduceDetail pp = new PProduceDetail();
				BeanUtils.copyProperties(ppDetail, pp);
				return pProduceDetailDao.insertSelective(pp);
			}

			
			public List<PProduceDetailBean> queryDetailsByProduceId(int proId) {
				List<PProduceDetailBean> listPPDBean = null;
				List<PProduceDetail> listPPD = pProduceDetailDao.queryDetailsByProduceId(proId);
				if(listPPD!=null&&listPPD.size()>0){
					listPPDBean = new ArrayList<PProduceDetailBean>();
					for (PProduceDetail ppd : listPPD) {
						PProduceDetailBean ppdBean = new PProduceDetailBean();
						BeanUtils.copyProperties(ppd, ppdBean);
						listPPDBean.add(ppdBean);
					}
				}
				return listPPDBean;
			}
			
			
			public List<PProduceDetailBean> queryDetailsWithProPlanByProduceId(int proId) {
				List<PProduceDetailBean> listPPDBean = null;
				List<PProduceDetail> listPPD = pProduceDetailDao.queryDetailsWithProPlanByProduceId(proId);
				if(listPPD!=null&&listPPD.size()>0){
					listPPDBean = new ArrayList<PProduceDetailBean>();
					for (PProduceDetail ppd : listPPD) {
						PProduceDetailBean ppdBean = new PProduceDetailBean();
						BeanUtils.copyProperties(ppd, ppdBean);
						listPPDBean.add(ppdBean);
					}
				}
				return listPPDBean;
			}
			

			
			public void deleteByProduceId(int proId) {
				pProduceDetailDao.deleteByProduceId(proId);
			}

			
			public void deleteById(int detailId) {
				pProduceDetailDao.deleteByPrimaryKey(detailId);
			}

			
			public PageInfoBean<PProduceDetailBean> queryDetailsByUserId(
					Map<String, Object> map) {
				List<PProduceDetailBean> listPPDBean = null;
				List<PProduceDetail> listPPD = pProduceDetailDao.queryDetailsByUserId(map);
				int count = pProduceDetailDao.queryCountDetailsByUserId(map);
				if(listPPD!=null&&listPPD.size()>0){
					listPPDBean = new ArrayList<PProduceDetailBean>();
					for (PProduceDetail ppd : listPPD) {
						PProduceDetailBean ppdBean = new PProduceDetailBean();
						BeanUtils.copyProperties(ppd, ppdBean);
						listPPDBean.add(ppdBean);
					}
				}
				
				return new PageInfoBean<PProduceDetailBean>(listPPDBean, count);
			}

			
			public int updateByPrimaryKey(PProduceDetailBean ppDetail) {
				if(ppDetail==null||ppDetail.getId()==null)
					return 0;
				PProduceDetail pp = new PProduceDetail();
				BeanUtils.copyProperties(ppDetail, pp);
				return pProduceDetailDao.updateByPrimaryKeySelective(pp);
			}

			
			public PProduceDetailBean findById(Integer id) {
				if(id==null||id<1)
					return null;
				PProduceDetail detail = pProduceDetailDao.selectByPrimaryKey(id);
				PProduceDetailBean bean = new PProduceDetailBean();
				BeanUtils.copyProperties(detail, bean);
				return bean;
			}

}